package com.taptech.doufu.db.noveledit;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.taptech.doufu.constant.Constant;

public class NovelEditDBHelper extends SQLiteOpenHelper {
    private final static String DBNAME = "novel_edit.db";
    public final static String TABLE_NAME = "novel_edit_table";

    public NovelEditDBHelper(Context context) {
        super(context, DBNAME, null, Constant.DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        Cursor cursor = null;
        try {
            cursor = db.rawQuery(
                    "SELECT * FROM sqlite_master WHERE type = ? AND name = ?",
                    new String[] { "table", TABLE_NAME });
            if (cursor.moveToNext()) {
            } else {
                db.execSQL("CREATE TABLE " + TABLE_NAME + " ("+
                        "_ID INTEGER PRIMARY KEY autoincrement, "
                        + "novel_id VARCHAR(1024), "    //小说ID
                        + "chapter_id VARCHAR(1024), "   //章节ID，新建章节使用特殊ID标记（-1）
                        + "chapter_title VARCHAR(1024), "  //章节标题
                        + "chapter_content TEXT, "    //章节内容
                        + "chapter_flag INTEGER, "    //0是草稿，1是已发布章节，2是新建
                        + "chapter_state INTEGER, "    //1表示临时数据 ,0是正常数据
                        + "created_at DATETIME, "    //创建时间
                        + "uid VARCHAR(1024), "    //用户ID
                        + "novel_author_say VARCHAR(1024)"  //作者有话说
                        + ");");
            }
            cursor.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
